﻿<!DOCTYPE html>
<html>
<head>
    <title>流程查询</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="Access-Control-Allow-Origin" content="*" />

    <link href="../DataUser/Style/ccbpm.css" rel="Stylesheet" />
    <script type="text/javascript" src="Scripts/QueryString.js"></script>
    <script type="text/javascript" src="Scripts/QueryString2016.js"></script>
    <script type="text/javascript" src="Scripts/jquery-1.7.2.min.js"></script>
    <script type="text/javascript" src="Scripts/bootstrap/js/jquery.min.js"></script>
    <script type="text/javascript" src="Scripts/bootstrap/js/jquery.cokie.min.js"></script>
    <!-- 导入配置文件. -->
    <script type="text/javascript" src="Scripts/config.js"></script>
    <script type="text/javascript" src="Comm/Gener.js"></script>
    <script type="text/javascript">

        var webUser = null;

        $(function () {

            webUser = new WebUser();
            if (webUser.No == null)
                return;

            var url = "";

            var _tspan = GetQueryString("TSpan");
            if (_tspan == undefined || _tspan == null || _tspan == "" || _tspan == "null") {
                _tspan = "-1";
            }

            var _flowNo = GetQueryString("FK_Flow");
            if (_flowNo == undefined || _flowNo == null || _flowNo == "" || _flowNo == "null") {
                _flowNo = "";
            }

            if (_flowNo == "" && _tspan == "")
                _tspan = "-1";

            var handler = new HttpHandler("BP.WF.HttpHandler.CCMobile");
            handler.AddPara("TSpan", _tspan);
            handler.AddPara("FK_Flow", _flowNo);
            var data = handler.DoMethodReturnString("Search_Init");

            if (data.indexOf('err@') == 0) {
                $("#Msg").html(data);
                return;
            }

            var data = JSON.parse(data);

            //时间段列表. 
            var tSpans = data['TSpan'];
            if (_tspan == "-1")
                html = "<span onclick=\"TSpan('');\" style='background-color:green;color:White;' >全部</span>";
            else
                html = "<span onclick=\"TSpan('');\"  >全部</span>";

            for (var i = 0; i < tSpans.length; i++) {

                var tSpan = tSpans[i];

                if (_tspan == tSpan.IntKey)
                    html += "<span onclick=\"TSpan('" + tSpan.IntKey + "');\" style='background-color:green;color:White' >" + tSpan.Lab + "</span>";
                else
                    html += "<span onclick=\"TSpan('" + tSpan.IntKey + "');\" >" + tSpan.Lab + "</span>";
            }

            html += "&nbsp;&nbsp;<img src='./Img/Search.png' border=0 style='width:16px;' />关键字:<input type=text id='TB_Key' style='width:90px;height:18px;' /><a href='#' onclick=\"javascript:SearchKey();\" > <b>查询</b> </a>";

            $("#TSpan").html(html);


            //流程名称列表.
            var flows = data['Flows'];
            if (_flowNo == null || _flowNo == "")
                html = "<span onclick=\"Flows('');\" style='background-color:green;color:White' >全部</span>";
            else
                html = "<span onclick=\"Flows('');\"  >全部</span>";

            for (var i = 0; i < flows.length; i++) {
                var en = flows[i];

                if (_flowNo == en.No)
                    html += "<span onclick=\"Flows('" + en.No + "');\"  style='background-color:green;color:White' >" + en.Name + "（" + en.Num + "）</span>";
                else
                    html += "<span onclick=\"Flows('" + en.No + "');\" >" + en.Name + "（" + en.Num + "）</span>";
            }
            $("#Flows").html(html);


            // 流程实例列表.
            var ens = data['WF_GenerWorkFlow'],
                        _Html = "";

            //当前登录人员的编号.
            var userNo = webUser.No;
            var todoEmpsName = "";
            for (var i = 0; i < ens.length; i++) {
                var en = ens[i];

                var fk_flow = en.FK_Flow,
                            fk_node = en.FK_Node,
                            workid = en.WorkID,
                            fid = en.FID,
                            isRead = en.IsRead,
                            paras = en.AtPara;

                if (paras == null || paras == "") {
                    paras = "";
                }
                else {
                    if (paras.indexOf("IsCC=1") > -1) {
                        paras = "IsCC=1";
                    } else {
                        paras = "";
                    }
                }

                todoEmpsName = en.TodoEmps;

                if (todoEmpsName != null)
                    todoEmpsName = en.TodoEmps.substr(todoEmpsName.indexOf(',') + 1);

                //是否可以执行当前工作?
                var isCanDo = false;
                if (en.TodoEmps != null) {
                    if (en.TodoEmps.indexOf(webUser.No) != -1)
                        isCanDo = true;
                }

                //获得icon.
                var icon = GenerICON(isCanDo, en.WFState);

                // 获得颜色.
                var color = GenerColor(en.WFState, isCanDo);

                html = "<tr >";
                html += "<td class=Idx>" + (i + 1) + "</td>";

                html += "<td><a href=\"javascript:OpenIt('" + en.WFState + "','" + en.WorkID + "','" + en.FK_Flow + "','" + en.FK_Node + "','" + en.TodoEmps + "','" + userNo + "')\"><img src=" + icon + " border=0 width='18px;' />" + en.Title + "</td>";

                html += "<td><font color='" + color + "'>" + en.StarterName + "</font></td>";

                html += "<td><font color='" + color + "'>" + en.RDT.substring(5) + "</font></td>";

                html += "<td><font color='" + color + "'>" + en.NodeName + "</font></td>";

                html += "<td><font color='" + color + "'>" + todoEmpsName + "</font></td>";

                html += "<td><font color='" + color + "'>" + en.RDT.substring(5) + "</font></td>";

                html += "<td><font color='" + color + "'>" + GetWFState(en.WFState, isCanDo) + "</font></td>";

                html += "<td><font color='" + color + "'>" + GenerOper(en.WorkID, en.WFState, en.FK_Flow, en.FK_Node, en.FID, isCanDo) + "</font></td>";

                html += "</tr>";
                $("#Table1 tr:last").after(html);
            }

            $("#List").append(_Html);
            $("#Msg").html("");

            //$("#LV_Search").listview('refresh');
        });


        function GenerOper(workID, wfState,flowNo,nodeID,fid,isCanDo) {

            if (wfState == 3)
                return "";

            if (wfState == 2 && isCanDo == true)
                return "";

            if (wfState == 3)
                return "<a href=''>轨迹</a>";

            if (wfState == 2)
                return "<a href=\"javascript:UnSend('"+flowNo+"','"+nodeID+"','"+workID+"','"+fid+"');\" >撤销</a>";


            var url = "WFRpt.htm?WorkID=" + workID + "&FK_Flow=" + flowNo;

            return "<a href=\"javascript:WinOpen('"+url+"');\" >轨迹</a>";
        }

        function UnSend(flowNo, nodeID, workid, fid) {

            if (confirm("您确定要撤销吗？") == false)
                return;

            var handler = new HttpHandler("BP.WF.HttpHandler.WF_WorkOpt_OneWork");
            handler.AddPara("FK_Node", nodeID);
            handler.AddPara("FK_Flow", flowNo);
            handler.AddPara("WorkID", workid);
            handler.AddPara("FID", fid);
            var data = handler.DoMethodReturnString("OP_UnSend");
            alert(data);
            window.location.href = window.location.href;
        }
        function GenerColor(wfState, isCanDo) {

            if (isCanDo == true && wfState != 3)
                return "red";

            if (wfState == 5) {
                return "yellow";
            }

            if (wfState == 3) {
                return "green";
            }

            if (wfState == 2)
                return "";

            return "";
        }

        function GetWFState(wfState, isCanDo) {

            if (isCanDo == true && wfState!=3)
                return "待办";

            if (wfState == 5) {
                return "退回";
            }

            if (wfState == 3) {
                return "已完成";
            }

            if (wfState == 2)
                return "运行中";

            return "其他";
        }
        function GenerICON(isCanDo, wfState) {

            if (wfState == 3)
                icon = "./Img/WFState/Complete.png";  //已经完成.
            else if (wfState == 2)
                icon = "./Img/WFState/Runing.png"; //运行中. 
            else if (wfState == 5)
                icon = "./Img/WFState/ReturnSta.png"; //退回.
            else
                icon = "./Img/WFState/Etc.png"; //其他.

            if (isCanDo == true && wfState != 3)
                icon = "./Img/WFState/Todo.png"; //其他.

            return icon;
        }

        function OpenIt(wfState, workid, flowNo, nodeID, emps, userNo) {

            var url = "";

            if (wfState != 3 && emps.indexOf(userNo) >= 0) {
                url = "MyFlow.htm?WorkID=" + workid + "&FK_Flow=" + flowNo + "&FK_Node=" + nodeID;
            } else {
                url = "WFRpt.htm?WorkID=" + workid + "&FK_Flow=" + flowNo;
            }
            //window.location.href = url;
            WinOpen(url);
        }

        function TSpan(tspan) {

            var flowNo = GetQueryString("FK_Flow");
            if (flowNo == null) {
                if (tspan == '')
                    window.location.href = '?1=1';
                else
                    window.location.href = '?TSpan=' + tspan;
            }
            else {
                if (tspan == '')
                    window.location.href = '?FK_Flow=' + flowNo;
                else
                    window.location.href = '?FK_Flow=' + flowNo + '&TSpan=' + tspan;
            }
        }
        

        function Flows(flowNo) {
            var tspan = GetQueryString("TSpan");

            if (tspan == null) {
                if (flowNo == "")
                    window.location.href = '?1=1';
                else
                    window.location.href = '?FK_Flow=' + flowNo;
            }
            else {

                if (flowNo == "")
                    window.location.href = '?TSpan=' + GetQueryString("TSpan");
                else
                    window.location.href = '?FK_Flow=' + flowNo + '&TSpan=' + GetQueryString("TSpan");
            }
        }
         
        function ToUrl(pageID) {
            var url = pageID + ".htm?m=" + Math.random();
            window.location.href = url;
        }

        function SearchKey() {

            var val = $("#TB_Key").val();
            if (val == null || val == undefined || val == "") {
                alert("请输入关键字,单据编号，标题。。。");
                return;
            }

            var handler = new HttpHandler("BP.WF.HttpHandler.WF_RptSearch");
            handler.AddPara("TB_KeyWords", val);

            var data = handler.DoMethodReturnString("KeySearch_Query");
            if (data.indexOf('err@') == 0) {
                alert(data);
                return;
            }

            //转化成json.
            data = JSON.parse(data);
            if (data.length <= 0) {
                alert('未查询出来数据');
                return;
            }

            var tableHtml = "<table class='Table'>";
            tableHtml += "<tr>";
            tableHtml += "<th>Idx</th>";
            tableHtml += "<th>标题</th>";
            tableHtml += "<th>发起人</th>";
            tableHtml += "<th>发起日期</th>";
            tableHtml += "<th>流程</th>";
            tableHtml += "<th>停留节点</th>";
            tableHtml += "<th>审批人</th>";
            tableHtml += "<th>到达日期</th>";
            tableHtml += "<th>状态</th>";
            tableHtml += "<th>操作</th>";
          //  tableHtml += "<th>参与人</th>";
            tableHtml += "</tr>";

            var user = new WebUser();
            var userNo = user.No;

            data.forEach(function (en, index) {

                var tr = "";

                //是否可以执行当前工作?
                var isCanDo = false;
                if (en.TodoEmps.indexOf(webUser.No) != -1)
                    isCanDo = true;

                //图片.
                var icon = GenerICON(isCanDo, en.WFState);

                // 获得颜色.
                var color = GenerColor(en.WFState, isCanDo);

                var todoEmpsName = en.TodoEmps;
                todoEmpsName = en.TodoEmps.substr(todoEmpsName.indexOf(',') + 1);

                html = "<tr>";
                html += "<td class=Idx>" + (index + 1) + "</td>";

                html += "<td><a href=\"javascript:OpenIt('" + en.WFState + "','" + en.WorkID + "','" + en.FK_Flow + "','" + en.FK_Node + "','" + en.TodoEmps + "','" + userNo + "')\"><img src=" + icon + " border=0 width='18px;' />" + en.Title + "</td>";

                html += "<td><font color='" + color + "'>" + en.StarterName + "</font></td>";

                html += "<td><font color='" + color + "'>" + en.RDT.substring(5) + "</font></td>";

                html += "<td><font color='" + color + "'>" + en.FlowName + "</font></td>";
                html += "<td><font color='" + color + "'>" + en.NodeName + "</font></td>";


                html += "<td><font color='" + color + "'>" + todoEmpsName + "</font></td>";

                html += "<td><font color='" + color + "'>" + en.RDT.substring(5) + "</font></td>";

                html += "<td><font color='" + color + "'>" + GetWFState(en.WFState, isCanDo) + "</font></td>";

                html += "<td><font color='" + color + "'>" + GenerOper(en.WorkID, en.WFState, en.FK_Flow, en.FK_Node, en.FID, isCanDo) + "</font></td>";

                //  html += "<td><font color='" + color + "'>" + en.Emps + "</font></td>";

                html += "</tr>";

                tableHtml += html;

            });

            tableHtml += "</table>";
            document.getElementById("Table1").innerHTML = tableHtml;
        }
    </script>
      <style type="text/css">
        span
        {
            display: inline-block;
            padding: 3px 5px;
            margin: 4px 5px;
            border: 1px dotted red;
            cursor: pointer;
        }
    </style>
</head>
<body>

<div id="Msg"> 
 <img src='./Img/loading.gif' alt="正在初始化数据，请耐心等待。。。" />正在初始化数据，请耐心等待。。。
 </div>


<table style="width:100%;">
<tr>
<td colspan=2 >
<div style="float:left">
<div id="TSpan"></div> <div id="Stas"></div> <div id="Flows"> </div>
</div>

<div style="float:right"> </div>

 </td>
</tr>

<tr>
<td colspan="2" >

<table id="Table1" style="width:100%;"> 
<tr>
<th>序</th>
<th>标题</th>
<th>发起人</th>
<th>发起日期</th>
<th>停留节点</th>
<th>审批人</th>
<th>到达日期</th>
<th>状态</th>
<th>操作</th>
</tr>
</table>

</td>

</tr>

</table>
     
                
        <div id="Msg">
        </div>
</body>
</html>
